<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="人员姓名" prop="faceName">
        <el-input
          v-model="queryParams.faceName"
          placeholder="请输入人员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="facePhone">
        <el-input
          v-model="queryParams.facePhone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        > -->
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="workshopList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="人员姓名" align="center" prop="faceName" />
      <el-table-column label="联系电话" align="center" prop="facePhone" />
      <el-table-column
        label="操作"
        align="center"
        width="200"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope" v-if="scope.row.userId !== 1">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleExportArr(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >移除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看 -->
    <el-dialog
      :title="title"
      :visible.sync="openQuery"
      center
      width="450px"
      append-to-body
    >
      <el-form ref="form" :model="formQuery" label-width="150px">
        <el-row>
          <el-col :span="20">
            <el-form-item prop="" label="人员姓名:">
              {{ formQuery.faceName }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="20">
            <el-form-item prop="" label="联系电话:">
              {{ formQuery.facePhone }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item prop="" label="照片:">
              <img style="width: 200px" :src="url + formQuery.paperUrl"
            /></el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelQuery">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  findShopRoster,
  deleteShopRoster,
  getShopRoster,
} from "@/api/shop/configuration/whitelist.js";

export default {
  data() {
    return {
      autoGenFlag: true,
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      workshopList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查看
      openQuery: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        organId: localStorage.getItem("organId"),
      },
      // 表单参数
      form: {},
      url: "http://192.168.50.191:8072/pics/",
      formQuery: {},
      // 表单校验
      rules: {
        workshopCode: [
          { required: true, message: "编码不能为空", trigger: "blur" },
        ],
        workshopName: [
          { required: true, message: "名称不能为空", trigger: "blur" },
        ],
        enableFlag: [
          { required: true, message: "是否启用不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      findShopRoster(this.queryParams).then((response) => {
        this.workshopList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancelQuery() {
      this.openQuery = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        organId: localStorage.getItem("organId"),
        shopName: "",
        shopLocation: "",
        runStatus: "",
        linkMan: "",
        linkPhone: "",
        startDate: "",
        endDate: "",
        startTime: "",
        endTime: "",
        whetherAllday: "",
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("form");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.workshopId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查看 **/
    handleExportArr(row) {
      console.log(row);
      const organId = row.id;
      this.openQuery = true;
      this.title = "查看";
      getShopRoster(organId).then((response) => {
        this.formQuery = response.data || [];
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workshopIds = row.id || this.id;
      deleteShopRoster({ id: workshopIds }).then((response) => {
        this.$modal
          .confirm('是否确认删除区域名称为"' + row.regionName + '"的数据项？')
          .then(() => {
            this.$modal.msgSuccess("删除成功");
            this.open = false;
            this.getList();
          })
          .catch(() => {});
      });
    },
  },
};
</script>
